package _15_generics._15_12;

/**
 * 自限定类型
 * @param <T>
 */
public class _03_SelfBounding<T extends _03_SelfBounding<T>> {
    T element;

    _03_SelfBounding<T> set(T arg) {
        this.element = arg;
        return this;
    }

    T get() {
        return element;
    }

    public static void main(String[] args) {
        A a = new A();
        a.set(new A());
        a = a.set(new A()).get();
        a = a.get();
        C c = new C();
        c = c.setAndGet(new C());
    }
}

class A extends _03_SelfBounding<A> {
}

class B extends _03_SelfBounding<A> {
}

class C extends _03_SelfBounding<C> {
    C setAndGet(C arg){
        set(arg);
        return get();
    }
}

class D {}
//class E extends _03_SelfBounding<D>{}

class F extends _03_SelfBounding{}
